package com.xiami.controller;

import com.xiami.pojo.Dept;
import com.xiami.pojo.MyResponseResult;
import com.xiami.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
创建者:虾米糖
*/
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;


@GetMapping()
public MyResponseResult getDept(){
    List<Dept> list = deptService.list1();
    return MyResponseResult.ok(list);
}

    @DeleteMapping("/{id}")
    public MyResponseResult getDept(@PathVariable  Integer id){
        log.info("id:{}",id);
        deptService.list(id);
        return MyResponseResult.builder().code(200).msg("ok").build();
    }
    @PostMapping
    public MyResponseResult addDept(@RequestBody Dept dept){
        log.info("dept:{}",dept);
        deptService.addDept(dept);
        return MyResponseResult.builder().code(200).msg("ok").build();
    }
}
